package cn.webestar.scms.task.api.dto.Task;

import cn.webestar.scms.commons.api.LimitBody;
import cn.webestar.scms.task.entity.Task;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.springframework.util.StringUtils;

import java.util.Date;

@Data
@Schema(description = "TaskLimitDTO")
public class TaskLimitDTO extends LimitBody {

    @Schema(description = "租户")
    private Long cid;

    @Schema(description = "标题")
    private String title;

    @Schema(description = "创建人")
    private Long creator;

    @Schema(description = "更新人")
    private Long updater;

    @Schema(description = "创建时间")
    private Date createTime;

    @Schema(description = "更新时间")
    private Date updateTime;

    @Override
    public LambdaQueryWrapper<Task> toQueryWapper() {
        LambdaQueryWrapper<Task> queryWrapper = new LambdaQueryWrapper<>();
        if (cid!=null) {
            queryWrapper.eq(Task::getCid, cid);
        }
        if (StringUtils.hasText(title)) {
            queryWrapper.eq(Task::getTitle, title);
        }
        if (creator!=null) {
            queryWrapper.eq(Task::getCreator, creator);
        }
        if (updater!=null) {
            queryWrapper.eq(Task::getUpdater, updater);
        }
        if (createTime!=null) {
            queryWrapper.eq(Task::getCreateTime, createTime);
        }
        if (updateTime!=null) {
            queryWrapper.eq(Task::getUpdateTime, updateTime);
        }
        queryWrapper.last("LIMIT " + this.getOffset() + "," + this.getLimit());
        return queryWrapper;
    }
    
}
